<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.fredck.FCKeditor.*,com.gouwudai.gobbs.pojo.TbbsUserInfo,com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsTopic,com.gouwudai.gobbs.pojo.TbbsTopicRe,com.gouwudai.gobbs.pojo.TbbsTopicContent"%>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass.jsp" %>
<%
String action = ParamUtils.getStringParameter(request,"action");

int classId = ParamUtils.getIntParameter(request, "classId", 0);
int topicId =  ParamUtils.getIntParameter(request,"topicId");	//如果topicId大于0则当前为回复，为0则是新的主题
int topicReId =  ParamUtils.getIntParameter(request,"topicReId");//当action为quote时，该ID为被引用的回复

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限验证模块 START *********************/
//1.判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//2.判断当前帖子是否存在
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
TbbsTopic tbbsTopic = null;

try
{
	tbbsTopic = topicService.load(new Integer(topicId));	
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的主题不存在或已被删除！");
	return;
}
//判断用户类型
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
else if(0==USER_ID.intValue())	//游客
{
	HtmlConst.errors(out,1,"您尚未登陆，无权进行此项操作！点击<a href=\"user_login_iframe2.jsp?TB_iframe=true&height=300&width=450\"  title=\"用户登陆\" class=\"thickbox\">此处</a>登陆");
	return;	
}

if(operatorType!=2) //非版主用户
{

	//判断当前用户浏览版面所需的等级
	if(userLogin.getGradeId().intValue()<currentClass.getAccessGrade())
	{
		HtmlConst.errors(out,1,"您的级别（"+ Arguments.getUserGradeName(userLogin.getGradeId()) +"）不能进行此项操作，如果你还没有登陆，请先登陆！");
		return;
	}	
	//如果该版面已被锁定，不能浏览
	if(currentClass.getClassPro().intValue()==2)
	{
		HtmlConst.errors(out,9,"该版面已被锁定！");
		return;
	}
	//如果该版面需要认证
	if(currentClass.getClassPro().intValue()==3)
	{
		boolean authFlag = classUserService.hasClassAuth(new Integer(classId),userLogin.getUserId());
		if(!authFlag)	
		{
			HtmlConst.errors(out,9,"该分类/版面需要认证！若需要浏览，请联系斑竹");
			return;
		}	
	}
	//判断主题状态
	if(tbbsTopic.getTopicPro().intValue()==1) //如果该主题已被锁定，不能浏览
	{
		HtmlConst.errors(out,9,"该主题已被锁定！");
		return;
	}	
	else if(tbbsTopic.getTopicPro().intValue()==4) //如果该主题已被禁止显示，不能浏览
	{
		HtmlConst.errors(out,9,"该主题已被禁止显示！");
		return;
	}
	
	//判断当前用户是否在黑名单当中
	if(operatorType==0)	//已登陆用户
	{
		IBlackListService blackListService = (IBlackListService)BeanManager.getBean("blackListService");
		String blackInfo = blackListService.isBlack(classId,USER_ID,2);//禁止回复主题黑名单
		if(!blackInfo.equals(""))
		{			
			HtmlConst.errors(out,10,blackInfo);
			return;
		}		
	}	
}
/***************** 权限验证模块 END *********************/
//------------------- 拼导航菜单 -----------------
//分类相关属性
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
//--------------------- 拼导航菜单 ----------------------------
//--------------------- 读取主题回复信息 --------------------------
ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");

TbbsTopicRe tbbsTopicRe = null;
//1.判断当前版面是否存在
try
{	
	tbbsTopicRe = topicReService.load(tbbsTopic.getTopicReId());
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的回复不存在或已被删除！");
	return;
}

int topicType = tbbsTopic.getTopicType().intValue();

//引用回复的一些对象
TbbsTopicRe quoteTopicRe = null;
StringBuilder quoteContent = new StringBuilder(200);

if(action.equals("quote")&&topicReId>0)	//如果当前动作为引用，读取引用的回复
{
	try
	{	
		quoteTopicRe = topicReService.load(topicReId);
	}
	catch(Exception e)
	{
		HtmlConst.errors(out,7,"您引用的主题不存在或已被删除！");
		return;
	}	
	quoteContent.append("[quote=\"");
	if(Utility.isEmpty(quoteTopicRe.getLoginId()))
		quoteContent.append("过客");
	else
	    quoteContent.append(quoteTopicRe.getLoginId());
	quoteContent.append("\"]");
	//quoteContent.append(quoteTopicRe.getTitle());
	
	if(topicReId==tbbsTopic.getTopicReId().intValue())	//如果引用的是楼主的内容
	{	
		if((topicType==2||topicType==3||topicType==4)||tbbsTopic.getTopicPro().intValue()==4||quoteTopicRe.getRePro().intValue()==1)//则要判断TOPIC_TYPE不能是“积分浏览”、“金币购买”、“回复可见”，如果回复的属性是“禁止显示”则也显示禁止显示
		{		
			quoteContent.append("\n");
			quoteContent.append("[color=#ff0000]&lt;您无法引用该内容&gt;[/color]");
		}	
		else
		{
			quoteContent.append("\n");
			quoteContent.append(Arguments.getTopicQuoteContent(topicReId));	
		}	
	
	}
	else //如果是其他人的回复，回复的属性是“禁止显示”则也显示禁止显示
	{
		if(quoteTopicRe.getRePro().intValue()==1)
		{
			quoteContent.append("\n");
			quoteContent.append("[color=#ff0000]&lt;您无法引用该内容&gt;[/color]");
		}
		else
		{
			quoteContent.append("\n");
			quoteContent.append(Arguments.getTopicQuoteContent(topicReId));		
		}
	}
	quoteContent.append("[/quote]");
}	

String title = tbbsTopicRe.getTitle();
TbbsUserInfo tbbsUserInfo = null;
if(USER_ID.intValue()>0)	//如果用户已登陆
{	
	IUserService userService = (IUserService)BeanManager.getBean("userService");
	tbbsUserInfo = userService.load(USER_ID);
}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - 回复主题 - <%=title %></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" type="text/javascript" src="scripts/validateTopic.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - 回复主题 -  <%=title %>');

var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT,false);
function doSubmit() 
{	
	form = document.theform;
	if(!validateForm(form))
		return false;
		
    var obj = {};    
    
	obj[Buffalo.BOCLASS] = "java.util.HashMap";
	
	obj.classId = <%=classId%>;
	obj.classParentId = <%=parentId%>;
	obj.grandId = <%=grandId%>;		
	
	obj.topicId = <%=topicId%>;
	obj.title =  $F('title');
	
	var loginIdOld = "<%=userLogin.getLoginId()%>";
	var passwordOld = "<%=userLogin.getPassword()%>";
	
	var userId = <%=userLogin.getUserId()%>;	
	var loginId = trim($F('loginId'));
	var password = $F('password');
	var loginIp = "<%=request.getRemoteAddr()%>";
	
	var successFlag = true;	//成功登陆标志
	if(loginId!="")		//以用户方式发表回复
	{		
		if(loginId!=loginIdOld)	//原来已经登陆过；或者现在输入了用户名现在修改了登陆名要重新登陆
		{
			successFlag = false;
			buffalo.remoteCall("userServiceAjaxService.userLoginAjax",[loginId,password,loginIp], function(reply) 
		    {
		       	var ret = reply.getResult();
		       	var params = parseAjaxReturn(ret);			
		       	if(params=="error")
		       	{
		       		sl_alert(ret);
		       		successFlag = false;
		       	}
		       	else
		       	{		
		       		userId = getParamValue(params,"userId");	       		
		       		loginId = getParamValue(params,"loginId");	       	
		       		successFlag = true;
		        }  
		       	    	
		    });	 	
    	}		
	}
	else //以游客方式发表回复
	{
		if(loginIdOld!="")	//原来已经登陆过，但是现在要以游客方式发表回复
		{
			userId = 0;
			loginId = "";
		}
	}
	if(!successFlag) return false;	
	
	obj.userId = userId;	
	obj.loginId = loginId;
	obj.topicAddIp = loginIp;

	var titleColor =  " ";
	var titleBold =  0;	
	<%//发表变色主题
	if(userLogin.withPermission(6002)){
	%>
		titleColor =  $F('titleColor');
	<%}		
	//发表粗体主题
	if(userLogin.withPermission(6001)){
	%>		
		titleBold =  $F('titleBold');
	<%}%>	
	obj.topicStyleList = titleColor+","+titleBold;
	
	obj.topicMood = getRadioValue("topicMood");	//没有选择心情则默认心情	
	
	obj.content = FCKeditorAPI.GetInstance('content').GetXHTML(true);
	obj.contentUserPen =  $F('contentUserPen');
	obj.contentEmail = $F('contentEmail');
	obj.contentCopyright = getRadioValue('contentCopyright');	
	
	var url = "topic_post.jsp?action=re&classId=<%=classId%>&topicId=<%=topicId%>"
    buffalo.remoteCall("topicServiceAjaxService.doReTopic",[obj], function(reply) 
    {
        var ret = reply.getResult();
       	ajaxSubmit(ret,"","location",url);        
    });   
}

</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;回复主题 -  <b><%=title %></b></DIV>
<DIV class="line"></DIV>
<form name="theform" id="theform" method="post" action="topic_post.jsp" onSubmit="return validateForm(this);">
<input name="action" type="hidden" value="re" />
<input name="topicId" type="hidden" value="<%=topicId%>" />
<input name="topicReId" type="hidden" value="<%=topicReId%>" />
<input name="classId" type="hidden" value="<%=classId%>" />
<input name="parentId" type="hidden" value="<%=parentId%>" />
<input name="grandId" type="hidden" value="<%=grandId%>" />
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
<tr>
<td width="80"  class="tab1"><strong>用户</strong></td>
<td class="bg2">
	<input name="loginId" type="text" id="loginId" value="<%=LOGIN_ID%>"  maxlength="50" onfocus="this.select();"   style="width:180px;height:20px" />
</td></tr>
<tr><td  class="tab1"><strong>密码</strong></td>
<td class="bg2">
	<input name="password" type="password" id="password" value="<%=userLogin.getPassword()%>" maxlength="50" onfocus="this.select();"  style="width:180px;height:20px"/>
	<input name="passwordOld" type="hidden" id="passwordOld" value="<%=userLogin.getPassword()%>"/>
</td></tr>
<tr><td  class="tab1"><strong>标题</strong></td>
<td class="bg2">
<input name="title" type="text" id="title" value="" maxlength="100" style="width:400px;height:20px"/>
<%//发表变色主题
if(userLogin.withPermission(6002)){
%>
<select name="titleColor" id="titleColor">
    <option selected value=" ">主题颜色</option>
    <option style="COLOR: #000000" value="black">■■■■</option>
    <option style="COLOR: #ff0000" value="#ff0000">■■■■</option>
    <option style="COLOR: #ffcc00" value="#ffcc00">■■■■</option>
    <option style="COLOR: #ff6699" value="#ff6699">■■■■</option>
    <option style="COLOR: #008800" value="#008800">■■■■</option>
    <option style="COLOR: orange" value="orange">■■■■</option>
    <option style="COLOR: #aa00cc" value="#aa00cc">■■■■</option>
    <option style="COLOR: #0000ff" value="#0000ff">■■■■</option>
    <option style="COLOR: #ccaa00" value="#ccaa00">■■■■</option>
    <option style="COLOR: #880000" value="#880000">■■■■</option>
    <option style="COLOR: teal" value="teal">■■■■</option>
    <option style="COLOR: #000088" value="#000088">■■■■</option>
	</select>
<%}
//发表粗体主题
if(userLogin.withPermission(6001)){
%>
&nbsp;<input name="titleBold" type="checkbox" id="titleBold" value="1">加粗
<%}%>
  </td>
</tr>
<tr id="load_<%=classId%>">
<td  class="tab1"><strong>心情</strong></td>
<td class="bg2">
<script language="javascript">
for(i=1; i<21; i++){
	document.write("<input type=\"radio\" name=\"topicMood\" value=\""+i+"\"/> ");		
	document.write("<img alt=\"心情"+i+"\" src=\"images/mood/"+i+".gif\" />&nbsp;&nbsp;");
	if(i==10){
		document.write("<br/>");
	}
}</script>
</tr>
<tr>
  <td  class="tab1"><strong>正文</strong></td>
  <td class="bg2">
  <%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( contextPath+"/fckeditor/" ) ;
oFCKeditor.setValue(quoteContent.toString());
oFCKeditor.setHeight("400");
FCKeditorConfigurations fckConfig = oFCKeditor.getConfig();
fckConfig.put("LinkBrowser","true");//超链浏览
fckConfig.put("ImageBrowser","true");//图片浏览
fckConfig.put("FlashBrowser","true");//FLASH浏览
fckConfig.put("LinkUpload","true");//文件上传
fckConfig.put("ImageUpload","true");//图片上传
fckConfig.put("FlashUpload","true");//FLASH上传
oFCKeditor.setConfig(fckConfig);
out.println( oFCKeditor.create() ) ;
%>	 
</td></tr>
<tr><td  class="tab1"><strong>上传附件</strong>
</td>
<td class="bg2">
<%
if(SYSINFO.getUpfileOpenFlag().booleanValue()&&userLogin.getUpfileOpenFlag().booleanValue()){%>
	<iframe name="uploadImg" frameborder=0 width="100%" height="30" scrolling=no src="uploading/index.jsp?uploadType=2" allowTransparency="true"></iframe>
<%}else{	
	out.print("<span style=\"remark\">此功能已被关闭</span>");	
}
%>
</td></tr>
<tr><td  class="tab1"><strong>辅助</strong></td>
<td class="bg2">
<input name="contentUserPen" type="checkbox" value="true"/>显示签名&nbsp;&nbsp;
<input name="contentEmail" type="checkbox" value="true"/>Email提醒
</td></tr>
<tr><td height="30" colspan="2"  class="tab1">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btnSubmit" type="button" class="btn" id="btnSubmit" value="  确定提交  " onClick="doSubmit();"/>
&nbsp;&nbsp;&nbsp;&nbsp;
<input name="btnBack" type="button" class="btn" onClick="javascript:history.back();" value="取消"/>
</td></tr>
<tr><td height="30" colspan="2"  class="tab1">
版权信息声明(仅代表发贴本人）：&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="0" checked/>无版权声明&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="1"/>本站独享&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="2"/>网络共享&nbsp;&nbsp;
<input id="contentCopyright" type="radio" name="contentCopyright" value="3"/>非商业性共享
</td></tr></table>
</form>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tab">
<tr class="tr">
	<td height="25" align="center"><%=Arguments.getUserInfoLink(tbbsTopic.getUserId(),tbbsTopic.getLoginId()) %></td>
	<td><%=Arguments.getTopicMoodDisplay(tbbsTopic.getTopicMood()) %>
	<%=Arguments.getTopicLink(tbbsTopic,1) %></td>
</tr>		
<tr valign="top" class="bg2"><td width="109" height="37">
	</td><td>
	<DIV class="content"><%=Arguments.getTopicContent(operatorType,tbbsUserInfo,tbbsTopic,tbbsTopicRe) %></DIV>
</td></tr>
</table>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>